package ink.lovejinhu.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jinhu
 * created 2021-07-14 11:04
 */
public class Solution_0401 {
    public static void main(String[] args) {
        Solution_0401 solution_0401 = new Solution_0401();
        solution_0401.readBinaryWatch(9);
        System.out.println(solution_0401.readBinaryWatch(9));
    }

    /**
     * trunOn表示灯点的个数
     *
     * @param turnedOn
     * @return
     */
    public List<String> readBinaryWatch(int turnedOn) {

        /**
         * turnOn状态下表示的数字
         */
        int[] hour = {1, 2, 4, 8};
        int[] minute = {1, 2, 4, 8, 16, 32};
        List<String> res = new ArrayList<>();
        for (int i = 0; i <= turnedOn && i < hour.length; i++) { //
            List<Integer> v0 = this.getAllResult(hour, i, 0, 24);
            if (turnedOn - i > minute.length) {
                continue;
            }
            List<Integer> v1 = this.getAllResult(minute, turnedOn - i, 0, 60);
            if (v0.isEmpty()) {
                if (v1.isEmpty()) {
                    res.add("0:00");
                } else {
                    for (int v3 : v1
                    ) {
                        if (v3 >= 10) {
                            res.add("0:" + v3);
                        } else {
                            res.add("0:0" + v3);
                        }

                    }
                }
            } else {
                if (v1.isEmpty()) {
                    for (int v2 : v0
                    ) {
                        res.add(v2 + ":00");

                    }
                } else {
                    for (int v2 : v0
                    ) {
                        for (int v3 : v1
                        ) {
                            res.add("" + v2 + ":" + v3);
                        }

                    }
                }
            }

        }

        return res;
    }


    /**
     * n表示选取个数
     * left表示从哪里开始选
     *
     * @param temp
     * @param n
     * @param left
     * @return
     */
    public List<Integer> getAllResult(int[] temp, int n, int left, int target) {
        if (n == 0) return new ArrayList<>();
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = left; i < temp.length; i++) {
            List<Integer> allResult = getAllResult(temp, n - 1, i + 1, target);
            if (allResult.isEmpty()) {
                integers.add(temp[i]);
            } else {
                for (int j = 0; j < allResult.size(); j++) {
                    if (allResult.get(j) + temp[i] < target) {
                        integers.add(allResult.get(j) + temp[i]);  //i
                    }
                }
            }

        }
        return integers;
    }
}
